{include file="header"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            {if !$sel}
            <div class="layui-card-header">
                <div class="left">
                    <button class="layui-btn layui-btn-primary addline" onclick="xadmin.open('频道添加','{:url("channel/add")}',600,600)">新建频道</button>
                    <button class="layui-btn layui-btn-primary selobj" onclick="sel()" data-type="sel">选择对象</button>
                    <button class="layui-btn layui-btn-danger del" onclick="del()">删除</button>
                </div>
                <div class="right">
                    <form action="{:url('channel/index')}" method="get" class="layui-form layui-col-space5 hide">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" class="layui-input" name="keyword" value="{:request()->get('keyword')}" placeholder="输入要找的频道名称">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" type="submit">搜索</button>
                        </div>
                    </form>
                </div>
            </div>
            {/if}

            <div class="layui-card-body">
                <table class="layui-table layui-form">
                    <thead>
                    <tr>
                        <th></th>
                        <th>图标</th>
                        <th>原名称</th>
                        <th>其他名称</th>
                        <th>所在国家</th>
                    </tr>
                    </thead>
                    {volist name="lists" id="item"}
                    <tbody>

                    <tr class="tr_{$item.id}">
                        <td>
                            {if !$sel}
                            <a href="javascript:;" class="editbtn" onclick="xadmin.open('公司修改','{:url("channel/edit",["id"=>$item["id"]])}',600,600)">编辑</a>
                            <div style="display: none;" class="selone">
                                <input type="checkbox" class="id" name="selone" value="{$item.id}" lay-skin="primary" >
                            </div>
                            {else}
                            <div class="selone">
                                <input type="checkbox" class="id" name="selone" value="{$item.id}" lay-skin="primary" >
                            </div>
                            {/if}
                        </td>
                        <td>
                            {if $item.logo}
                            <img class="logo" src="{$item.logo|formatImg}" alt="" width="70">
                            {else}
                            /
                            {/if}
                        </td>
                        <td>
                            <span class="title">{$item.title}</span>
                        </td>
                        <td rowspan="2">{$item.title_other}</td>
                        <td rowspan="2">{$item.country}</td>
                    </tr>
                    </tbody>
                    {/volist}
                </table>

            </div>
            <div class="layui-card-body " style="text-align: center;">
                {$lists|raw}
                {if $sel}
                <button class="layui-btn" style="display: inline-block;height: 36px;" onclick="truesel()">确定</button>
                {/if}
            </div>
        </div>
    </div>
</div>
<script>
    function del() {
        var id;
        let seltype = $('.selobj').data("type")
        if(seltype==="sel"){
            id = [$('[name="selone"]').last().val()]
        }else{
            id = getselall()
        }

        layer.confirm("{:lang('del.confirm')}",{icon: 3, title:'{:lang("tips")}'},function (index) {
            layer.close(index);
            request("POST",'{:url("channel/del")}',{
                id:id
            },function (res) {
                for(let i in id){
                    $(`.tr_${id[i]}`).remove()
                }

            })

        })
    }
    function truesel() {
        var id = getselall()
        if(id.length<=0){
            layer.msg("请选择")
        }else{
            for(var item in id){

                var obj = $('.tr_'+id[item])

                var cid= obj.find('.id').val()
                var clogo = obj.find('.logo').attr("src")
                var ctitle = obj.find('.title').text()

                parent.addcompany(cid,ctitle,clogo)
            }
            xadmin.close();

        }
    }
</script>
{include file="footer"}